package ch4.ex12;

import static ch4.print.Print.*;

class Tank{
	static int counter;
	int i = counter++;
	boolean full;
	Tank(){
		println("Tank " + i + " was created.");
		full = true;
	}
	public void empty(){ full = false;}
	protected void finalize(){
		if(full)
		{
			println("Error: tank " + i + " must be empty at cleanup.");
		}
		else{
			println("Tank " + i + " cleaned up OK.");
		}
	}
	public String toString(){
		return "Tank " + i;
	}
}

public class TankTemination {
	public static void main(String[] args){
		new Tank().empty();
		new Tank();
		System.gc();
		System.runFinalization();
	}
	
	
}
